﻿namespace LogManager.Utils.IO
{
    using LogManager.TestUtility;
    using NUnit.Framework;
    using System;
    using System.IO;
    using System.Linq;

    public class TestPathHelper
    {
        public const string WORKING_DIR = "TestDir";

        [TestFixtureSetUp]
        public void Init()
        {
            Directory.CreateDirectory(WORKING_DIR);
        }

        [TestFixtureTearDown]
        public void CleanUp()
        {
            Directory.Delete(WORKING_DIR, true);
        }

        [Test]
        public void PathManager_GetFilesOlderThan_retreiveFilesForOldDuration_ok()
        {
            var fileName = "sampleFile";
            var fileFullName = WORKING_DIR + "\\" + fileName;

            var createdFile40 = FileUtility.CreateFile(fileFullName + "40", DateTime.Now.AddDays(-40));
            var createdFile20 = FileUtility.CreateFile(fileFullName + "20", DateTime.Now.AddDays(-20));
            var createdFile10 = FileUtility.CreateFile(fileFullName + "10", DateTime.Now.AddDays(-10));
            var createdFile5 = FileUtility.CreateFile(fileFullName + "5", DateTime.Now.AddDays(-5));

            var files = PathHelper.GetFilesOlderThan(WORKING_DIR, new TimeSpan(15, 0, 0, 0));

            Assert.AreEqual(2, files.Count);

            Assert.IsTrue(files.Any(f => f.FullName == createdFile40.FullName));
            Assert.IsTrue(files.Any(f => f.FullName == createdFile20.FullName));
        }

        [Test]
        public void PathManager_CheckFullAccessDirectory_CoverageTest_Ok()
        {         
            PathHelper.CheckFullAccessDirectory(WORKING_DIR);
        }
    }
}
